let fs = require('fs')
let path = require('path')

module.exports = function (req, res, next) {
  let name = req.url.split('/')[2] // req.query.name
  if (name) {
    res.set({
      "Content-type": "application/octet-stream",
      "Content-Disposition": `attachment;filename=${name}.pdf` //输出头部信息
    });
    let file = path.resolve(__dirname, `../pdf/${name}.pdf`)
    console.log('file', file)
    fs.readFile(file, function (err, data) {
      if (err) {
        console.log(err)
      } else {
        res.send(data)
      }
    })
  } else {
    res.send('preview');
  }

};